package com.hooya.fa.eu.biz.business;


import com.hooya.fa.eu.biz.business.service.*;
import com.hooya.fa.eu.biz.service.EuCheckService;
import com.hooya.fa.eu.biz.service.ResetSkuFlagService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequiredArgsConstructor
public class DateAggregation_02 {

	private final EuCheckService euCheckService;

	private final ResetSkuFlagService resetSkuFlagService;

	private final Insert_B2B insert_b2b;
	private final Insert_B2C insert_b2c;
	private final Insert_BS insert_bs;
	private final Insert_CG insert_cg;
	private final Insert_TH insert_th;
	private final Insert_ZY insert_zy;


	@GetMapping("/second")
	public void dateAggregation_02(String startDate, String endDate) {

		log.info("2.dateAggregation_02开始执行");

//		insertToStk_six(startDate);  // 完成

		post_test(startDate);	//完成

//		resetSkuFlag(startDate, endDate);  //完成

		log.info("2.dateAggregation_02执行完毕");

	}

	private void insertToStk_six(String startDate) {
		log.info("2.insertToStk_six开始执行");

		insert_b2b.insert_b2b(startDate);
		insert_b2c.insert_b2c(startDate);
		insert_bs.insert_bs(startDate);
		insert_cg.insert_cg(startDate);
		insert_th.insert_th(startDate);
		insert_zy.insert_zy(startDate);

		log.info("2.insertToStk_six执行完毕");
	}

	private void post_test(String startDate) {

		log.info("2.post_test开始执行");

		try {
			log.info("2.test_qty_changes开始执行");
			euCheckService.checkStockQty(startDate);
			log.info("2.test_qty_changes执行完毕");
		} catch (Exception e) {
			log.error("2.test_qty_changes执行异常");
			throw new RuntimeException("2.test_qty_changes执行异常", e);
		}

		try {
			log.info("2.test_sheetnumber开始执行");
			euCheckService.checkAndContrastStockList(startDate);
			log.info("2.test_sheetnumber执行完毕");
		} catch (Exception e) {
			log.error("2.test_sheetnumber执行异常");
			throw new RuntimeException("2.test_sheetnumber执行异常", e);
		}

		log.info("2.post_test执行完毕");
	}

	private void resetSkuFlag(String startDate, String endDate) {

		log.info("2.reset_sku_flag开始执行");
		resetSkuFlagService.reset_sku_flag(startDate, endDate);
		log.info("2.reset_sku_flag执行完毕");

	}

}
